--- @param extension Package
--- @param HY HY_Utility
--- @param U Utility
return function(extension, HY, U)
    local hy_usami_sumireko = General:new(extension, "hy_usami_sumireko", "jin_k", 4, 4, General.Female)
    local mental_power = fk.CreateSkill {
        name = "mental_power",
    }
    mental_power:addEffect("active", {
        target_num = 0,
        card_num = 0,
        target_filter = Util.FalseFunc,
        card_filter = Util.FalseFunc,
        can_use = function(self, player)
            return player:usedSkillTimes(mental_power.name, Player.HistoryPhase) < 1
        end,
        prompt = "mental_power_prompt",
        on_use = function(self, room, cardUseEvent)
            local player = cardUseEvent.from
            local cards = room:getNCards(2)
            local result = room:askToYiji(player, {
                cards = cards,
                min_num = 0,
                max_num = #cards,
                targets = room:getAlivePlayers(),
                skill_name = mental_power.name,
                prompt = "mental_power_prompt_distribution",
                expand_pile = cards
            })
            if table.sum(result, function(value)
                    return #value
                end) == #cards then
                room:loseHp(player, 1, mental_power.name)
                player:setSkillUseHistory(mental_power.name, 0, Player.HistoryPhase)
            end
        end,
    })
    local freakery = fk.CreateSkill {
        name = "freakery",
        tags = {
            Skill.Charge
        }
    }
    freakery:addEffect(fk.AfterSkillEffect, {
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(self) then
                return false
            end
            return data.skill.name == "mental_power" and target == player and player:getMark("skill_charge") < player:getMark("skill_charge_max")
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            U.skillCharged(player, 1)
        end,
    })
    freakery:addEffect(fk.EventPhaseStart, {
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(self) then
                return false
            end
            return player:getMark("skill_charge") > 0 and target == player and target.phase == Player.Finish
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local choices = {}
            for i = 1, player:getMark("skill_charge") do
                table.insert(choices, tostring(i))
            end
            table.insert(choices, "Cancel")
            event:setCostData(self, room:askToChoice(player, {
                choices = choices,
                skill_name = freakery.name,
                prompt = "freakery_prompt"
            }))
            return event:getCostData(self) ~= "Cancel"
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local count = tonumber(event:getCostData(self))
            U.skillCharged(player, -count)
            local cards = room:drawCards(player, count * 2, freakery.name)
            for _, id in ipairs(cards) do
                room:setCardMark(Fk:getCardById(id), "@@freakery-inhand", 1)
            end
        end,
    })
    freakery:addEffect(fk.Damaged, {
        can_trigger = function(self, event, target, player, data)
            if not player:hasSkill(self) then
                return false
            end
            return player:getMark("skill_charge") > 0 and target == player
        end,
        on_cost = function(self, event, target, player, data)
            local room = player.room
            local choices = {}
            for i = 1, player:getMark("skill_charge") do
                table.insert(choices, tostring(i))
            end
            table.insert(choices, "Cancel")
            event:setCostData(self, room:askToChoice(player, {
                choices = choices,
                skill_name = freakery.name,
                prompt = "freakery_prompt"
            }))
            return event:getCostData(self) ~= "Cancel"
        end,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local count = tonumber(event:getCostData(self))
            U.skillCharged(player, -count)
            local cards = room:drawCards(player, count * 2, freakery.name)
            for _, id in ipairs(cards) do
                room:setCardMark(Fk:getCardById(id), "@@freakery-inhand", 1)
            end
        end,
    })
    freakery:addAcquireEffect(function(self, player, is_start)
        U.skillCharged(player, 2, 4)
    end)
    freakery:addLoseEffect(function(self, player, is_death)
        U.skillCharged(player, 0, -4)
    end)
    freakery:addEffect(fk.EventPhaseEnd, {
        can_refresh = function(self, event, target, player, data)
            return target == player and target.phase == Player.Play and #player:getTableMark("freakery_cards") > 0
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local cards = table.filter(player:getTableMark("freakery_cards"), function(id)
                return Fk:getCardById(id):getMark("@@freakery-inhand") > 0
            end)
            room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, freakery.name)
            room:setPlayerMark(player, "freakery_cards", {})
        end
    })
    freakery:addEffect(fk.CardUseFinished, {
        can_refresh = function(self, event, target, player, data)
            local room = player.room
            return room.current == player and #room.logic:getEventsOfScope(GameEvent.UseCard, 999, function(e)
                return e.data.from == player
            end, Player.HistoryTurn) >= player:getMark("skill_charge") + 1 and #player:getTableMark("freakery_cards") > 0
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local cards = table.filter(player:getTableMark("freakery_cards"), function(id)
                return Fk:getCardById(id):getMark("@@freakery-inhand") > 0
            end)
            room:moveCardTo(cards, Card.DiscardPile, nil, fk.ReasonPutIntoDiscardPile, freakery.name)
            room:setPlayerMark(player, "freakery_cards", {})
        end
    })
    freakery:addEffect(fk.TurnEnd, {
        can_refresh = function(self, event, target, player, data)
            return #table.filter(player:getCardIds("h"), function(id)
                return Fk:getCardById(id):getMark("@@freakery-inhand") > 0
            end) > 0
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local cards = table.filter(player:getCardIds("h"), function(id)
                return Fk:getCardById(id):getMark("@@freakery-inhand") > 0
            end)
            local marks = player:getTableMark("freakery_cards")
            table.insertTableIfNeed(marks, cards)
            room:setPlayerMark(player, "freakery_cards", marks)
        end
    })
    local peek_mystery = fk.CreateSkill {
        name = "peek_mystery",
        tags = {
            Skill.Lord
        }
    }
    peek_mystery:addEffect(fk.HpLost, {
        times = function(self, player)
            return #table.filter(Fk:currentRoom().alive_players, function(t)
                return t.kingdom == "jin_k"
            end) - player:getMark("peek_mystery-round")
        end,
        can_trigger = function(self, event, target, player, data)
            return player:hasSkill(self) and player == target and player:getMark("peek_mystery-round") < #table.filter(player.room.alive_players, function(t)
                return t.kingdom == "jin_k"
            end)
        end,
        on_cost = Util.TrueFunc,
        on_use = function(self, event, target, player, data)
            local room = player.room
            local count = data.num
            local remain = #table.filter(room.alive_players, function(t)
                return t.kingdom == "jin_k"
            end) - player:getMark("peek_mystery-round")
            local max = player.maxHp - player.hp
            local actual = math.max(math.min(count, remain), 0)
            local recover = math.min(max, actual)
            room:recover({
                who = player,
                num = recover,
                skillName = peek_mystery.name,
                recoverBy = player
            })
            room:addPlayerMark(player, "peek_mystery-round", actual)
            room:addPlayerMark(player, "peek_mystery_record_pre", recover)
        end,
    })
    peek_mystery:addEffect(fk.TurnStart, {
        can_refresh = function(self, event, target, player, data)
            return player:getMark("peek_mystery_record") > 0 and target == player
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            local value = -player:getMark("peek_mystery_record")
            room:setPlayerMark(player, "peek_mystery_record", 0)
            room:changeHp(player, value, nil, peek_mystery.name)
        end,
    })
    peek_mystery:addEffect(fk.TurnEnd, {
        can_refresh = function(self, event, target, player, data)
            return player:getMark("peek_mystery_record_pre") > 0
        end,
        on_refresh = function(self, event, target, player, data)
            local room = player.room
            room:addPlayerMark(player, "peek_mystery_record", player:getMark("peek_mystery_record_pre"))
            room:setPlayerMark(player, "peek_mystery_record_pre", 0)
        end,
    })
    extension:loadSkillSkels { mental_power, freakery, peek_mystery }
    hy_usami_sumireko:addSkill("mental_power")
    hy_usami_sumireko:addSkill("freakery")
    hy_usami_sumireko:addSkill("peek_mystery")
    Fk:loadTranslationTable {
        ["hy_usami_sumireko"] = "宇佐见堇子",
        ["#hy_usami_sumireko"] = "异界怪客",
        ["designer:hy_usami_sumireko"] = "黑曜人形",
        ["illustrator:hy_usami_sumireko"] = "ゾウノセ",
        ["cv:hy_usami_sumireko"] = "",

        ["mental_power"] = "念力",
        [":mental_power"] = "出牌阶段限一次，你可以观看牌堆顶两张牌并分配其中任意张，若你以此法分配了全部牌，则失去1点体力并重置“念力”。",
        ["mental_power_prompt"] = "念力：你可以观看牌堆顶两张牌",
        ["mental_power_prompt_distribution"] = "念力：你可以分配其中任意张牌",

        ["freakery"] = "异想",
        [":freakery"] = "蓄力技（2/4），结束阶段或在你受到伤害后，你可以减少任意点蓄力点，然后<a href='temp_operation'>临时</a>摸两倍数量的牌直到你的下回合使用第X+1张牌结算结束后或出牌阶段结束时（X为你的蓄力点）。你每发动一次“念力”，获得1点蓄力点。",
        ["freakery_prompt"] = "异想：你可以减少任意点蓄力点并摸两倍的牌",
        ["@@freakery-inhand"] = "异想",

        ["peek_mystery"] = "窥谜",
        [":peek_mystery"] = "主公技，每轮限Y次，在你失去1点体力后，你<a href = 'temp_operation'>临时</a>回复1点体力直到你的下个回合开始时（Y为存活的人势力角色数）。",
    }
end
